#!/bin/sh
#
# beaker-transfer:	Start the Beaker log transfer daemon
#
# chkconfig: - 99 99
# description:  This service handles rsyncing logs to their final destination
#	
#

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/bin/beaker-transfer ] || exit 0

prog="beaker-transfer"
PIDFILE=/var/run/beaker-lab-controller/${prog}.pid
LOCKFILE=/var/lock/subsys/$prog
RUN_AS=apache

check_pidfile() {
    status -p $PIDFILE $prog >& /dev/null
    ret=$?
    if [ "$ret" -eq 1 ]; then
        # remove stale pidfile
        rm -f -- "$PIDFILE"
    fi
}

start() {
    echo -n $"Starting $prog: "
    check_pidfile
    daemon --pidfile $PIDFILE --user $RUN_AS $prog
    RETVAL=$?
    echo
    if test $RETVAL = 0; then
        touch $LOCKFILE
    fi
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $PIDFILE $prog
    RETVAL=$?
    echo 
    rm -f $LOCKFILE
    return $RETVAL
}

restart() {
    stop
    start
}

condrestart(){
	[ -e $LOCKFILE ] && restart
	return 0
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status -p $PIDFILE $prog
	RETVAL=$?
        ;;
    restart)
	restart
	;;
    condrestart)
	condrestart
	;;
    reload)
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	;;
esac
exit $RETVAL
